#include <Assert.h>

#include <QDateTime>
#include <QCryptographicHash>
#include <QLocale>
#include <qDebug>

#include "AliOSSAdapter.h"

namespace AliOSS
{
    AliOSSAdapter::AliOSSAdapter(
        const QString &bucket,
        const QString &accessId,
        QObject *parent /*= nullptr*/)
        :QObject(parent), bucket(bucket), accessId(accessId),
        networkAccessManager(new QNetworkAccessManager(this))
    {

    }

    AliOSSAdapter::~AliOSSAdapter()
    {

	}

	AliOSSUploadRequest *AliOSSAdapter::prepareUpload(const QByteArray & data)
	{
		AliOSSUploadRequest *uploader = new AliOSSUploadRequest(this, networkAccessManager, bucket, accessId);
		uploader->prepare(data);
		return uploader;
	}

	AliOSSRemoveRequest * AliOSSAdapter::prepareRemove(const QString &path)
	{
		AliOSSRemoveRequest *removeRequest = new AliOSSRemoveRequest(this, networkAccessManager, bucket, accessId);
		removeRequest->prepare(path);
		return removeRequest;
	}

    AliOSS::AliOSSCopyRequest * AliOSSAdapter::prepareCopy(const QString &srcPath, const QString &dstPath)
    {
        AliOSSCopyRequest *copyRequest = new AliOSSCopyRequest(this, networkAccessManager, bucket, accessId);
        copyRequest->prepare(srcPath, dstPath);
        return copyRequest;
    }

    QString AliOSSAdapter::formatDatetime(QDateTime datetime)
	{
		QLocale eng(QLocale::English);
		return eng.toString(datetime, "ddd, dd MMM yyyy HH:mm:ss") + " GMT";
	}
}
